package com.nineclock.message.listener;

import com.nineclock.message.service.MessageService;
import com.nineclock.message.pojo.NcMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
//messagePushTopic与推送时使用的标题是一致的
@Component
@Slf4j
@RocketMQMessageListener(topic = "messagePushTopic",consumerGroup = "messagePushConsumer")
public class MsgConsumerListener implements RocketMQListener<NcMessage> { //这的泛型指的是要消费的对象的类型是什么


    @Autowired
    MessageService messageService;

    /**
     * 1. 把收到的消息存储到mongodb
     * 2. 把消息推送给主管理员
     * @param message
     */

    @Override
    public void onMessage(NcMessage message) {

        try {
            log.info(message.getApplyUsername()+"申请加入企业,管理员"+ message.getApproveUsername()+"审批");
            //推送消息
            messageService.pushSingleMessage(message);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
